2026-09-20 · linux, class-notes
Linux, like Windows, organises files into a hierarchy of directories (folders) that can contain files and further directories. The first directory is the root directory, written /. Everything else branches out from it.
Class notes · William Shotts, The Linux Command Line · Chapter 2
Quick reference: the short version of this chapter is the Chapter 2 cheat sheet.
By the end of these notes you should be able to:
Linux, like Windows, organises files into a hierarchy of directories (folders) that can contain files and further directories. The first directory is the root directory, written /. Everything else branches out from it.
/ <- root directory: the top of everything |-- bin |-- etc |-- home | |-- andrew <- your home directory (~) | | |-- Documents | | `-- Downloads | `-- katie |-- tmp `-- usr |-- bin |-- lib `-- share `-- doc
Windows
Linux
A separate tree per drive: C:\, D:\, E:\
One tree, always starting at /
New drives get a new letter
New drives are mounted at a directory somewhere in the tree, e.g. /media/andrew/USBSTICK
Backslash separator: C:\Users\andrew
Forward slash: /home/andrew
Mostly case-insensitive
Case-sensitive
The operating system decides where each storage device appears; a USB stick, a second disk and a network share all become ordinary directories in the same tree.
Imagine the tree as a maze of rooms. At any moment you're standing in one room: your current working directory. Commands act relative to it unless you say otherwise.
$ pwd /home/andrewpwd stands for print working directory.
When you first open a terminal, you start in your home directory:
ls lists the contents of a directory.
$ ls Desktop Documents Downloads Music Pictures Public Templates Videos
Form
Lists
ls
The current directory
ls /usr
A named directory
ls ~ /usr
Several directories, one after another
ls -a
Includes hidden files (names starting with .)
ls -l
Long format — permissions, owner, size, date
ls has many more options; chapter 3 covers them in depth.
cd (change directory) moves you to a new working directory. You tell it where to go with a pathname, and there are two kinds.
An absolute pathname starts at the root, so it always begins with /. It works from anywhere, because it describes the full route from the top of the tree.
$ cd /usr/bin $ pwd /usr/bin
A relative pathname starts from wherever you are now. Two special names make it work:
Symbol
Means
.
This directory (the current working directory)
..
The parent directory — one level up
$ cd /usr/bin $ cd .. \
$ pwd /usr $ cd ./bin \
$ pwd /usr/bin__./ is almost always optional.__ cd ./bin and cd bin do the same thing, because the shell assumes a name without a leading / is relative to the current directory.
Note: the one common exception is running a program in the current directory, such as ./myscript.sh. The shell doesn't search the current directory for commands, so there you must write ./. (This is covered later in the book.)
You're in /usr/share/doc and want to get to /usr/bin.
Absolute:
cd /usr/bin
Relative — work it out step by step:
cd ../../bin
Which to use?
Starting in /home/andrew, where does each command take you?
Command
Result
Reasoning
cd Documents
/home/andrew/Documents
Relative: down into Documents
cd ..
/home
Up one level
cd ../katie
/home/katie
Up to /home, then down into katie
cd /tmp
/tmp
Absolute: from the root
cd ../..
/
Up twice from /home/andrew
cd .. at /
/
You can't go above the root; .. of / is /
Shortcut
Takes you to
cd
Your home directory
cd ~
Your home directory
cd -
The previous working directory (and prints it)
cd ~katie
The home directory of user katie
$ cd /var/log $ cd /etc $ cd - \
/var/logcd - is handy when switching back and forth between two places, such as a config directory and a log directory while troubleshooting.
Filenames that begin with a dot are hidden. ls won't show them unless you use ls -a.
$ ls -a ~ . .. .bash_history .bash_logout .bashrc .cache .profile Documents Downloads- Why hide them? Most dotfiles are configuration files for your programs (.bashrc configures Bash). Hiding them keeps your home directory tidy.
Filenames are case-sensitive. File1, file1 and FILE1 are three different files, and they can all sit in the same directory.
Linux itself has no concept of file extensions. A file's contents, and its permissions, decide what it is and whether it can run. A script called backup with no extension runs as well as backup.sh.
Linux allows almost any character in a filename, including spaces. But many characters have special meaning to the shell, so they cause trouble later.
Safe to use
Avoid
Letters and digits
Spaces
Period .
* ? [ ] { } (wildcards and expansion)
Dash - (not as the first character)
$ & ; | < > ( ) ' " \ !`
Underscore _
A leading dash (-file looks like an option)
Worked example — spaces in names:
ls "my report.txt" ls my\ report.txt1. Better: name files my-report.txt or my_report.txt from the start.
Press Tab while typing a path and Bash completes it, or shows the options when there are several matches. It saves typing and prevents typos — and it handles awkward names (including spaces) for you. Use it constantly.
Term
Definition
Directory
A folder that holds files and other directories
Hierarchical directory structure
The tree arrangement of directories
Root directory (/)
The top of the Linux directory tree
Mounting
Attaching a storage device's file system at a directory in the tree
Current working directory
The directory you're "in"; relative paths start here
Home directory (~)
A user's personal directory, usually /home/
pwd
Print working directory
ls
List directory contents
cd
Change directory
Pathname
The route to a file or directory
Absolute pathname
A path starting at /
Relative pathname
A path starting from the current directory
. / ..
The current directory / the parent directory
cd -
Return to the previous working directory
Hidden file (dotfile)
A file whose name starts with .
Case-sensitive
Treating upper- and lower-case letters as different
Tab completion
Bash completing a partially typed name when you press Tab